<?php


namespace app\admin\model;


use think\Db;
use think\Model;

class BaseModel extends Model
{


    public static function getSupName($id){
        // 拼接查询条件hql
        $res=Db::name("cemetery")->where(array('is_delete'=>0,'id'=>$id))->field('id,name,type,parent_id')
            ->select()->toArray();
        // 得到一级数据
        if($res) {
            if($res[0]["parent_id"] != 0) {
                $result = self::getSupName($res[0]["parent_id"]);
            }else{
                $result = array();
            }
            $imgInfo = array_merge_recursive($res, $result);
        }else{
            $imgInfo = array();
        }
        return $imgInfo;
    }

    public static function getSup($id){
        // 拼接查询条件hql
        $res=Db::name("cemetery")->where(array('is_delete'=>0,'id'=>$id))
            ->select()->toArray();
        // 得到一级数据
        if($res) {
            if($res[0]["parent_id"] != 0) {
                $result = self::getSup($res[0]["parent_id"]);
            }else{
                $result = array();
            }
            $imgInfo = array_merge_recursive($res, $result);
        }else{
            $imgInfo = array();
        }
        return $imgInfo;
    }

    public  function  getPayNum($times,$sn,$zm,$start=3){
        $count = self::order('id DESC')->find();
        $time =date('Ymd');
        if(date('Ymd',$count[$times])==$time){
            $num = $zm.''.$time.''.str_pad(substr($count[$sn],-$start)+1, 3, '0', STR_PAD_LEFT);
        }else{
            $num =$zm.''.$time.''.str_pad(1, 3, '0', STR_PAD_LEFT);;
        }
        return $num;
    }
    public static function  getselfPayNum($times,$sn,$zm,$start=3){
        $count = self::where($sn,'like','%'.$zm.'%')->order('id DESC')->find();
        $time =date('Ymd');
        if(date('Ymd',$count[$times])==$time){
            $num = $zm.''.$time.''.str_pad(substr($count[$sn],-$start)+1, 3, '0', STR_PAD_LEFT);
        }else{
            $num =$zm.''.$time.''.str_pad(1, 3, '0', STR_PAD_LEFT);;
        }
        return $num;
    }
}